﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.Configuration;

namespace TravelLink.Common {
    public class LogWriter {

        private static readonly ILog _log;

        private static readonly string LogName = ConfigurationManager.AppSettings["LogName"];

        static LogWriter() {
            XmlConfigurator.Configure();
            string logName = string.IsNullOrEmpty(LogName) ? "TravelLink" : LogName;
            _log = LogManager.GetLogger(logName);
        }

        /// <summary>
        /// 写常规日志
        /// </summary>
        /// <param name="msg"></param>
        public static void Info(string msg) {
            _log.Info(msg);
        }

        /// <summary>
        /// 写程序调试日志
        /// </summary>
        /// <param name="msg"></param>
        public static void Debug(string msg) {
            _log.Debug(msg);
        }

        /// <summary>
        /// 写错误日志
        /// </summary>
        /// <param name="msg"></param>
        public static void Error(string msg) {
            _log.Error(msg);
        }

        /// <summary>
        /// 重载：错误日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="ex"></param>
        public static void Error(string msg, Exception ex) {
            _log.Error(msg, ex);
        }
    }
}
